package com.yenlien.traceyun.plant.controller;

import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.dao.EquipmentDao;
import com.yenlien.traceyun.business.entity.Equipment;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.plant.bean.CompareParamDTO;
import com.yenlien.traceyun.plant.dao.*;
import com.yenlien.traceyun.plant.bean.DevDTO;
import com.yenlien.traceyun.plant.dock_device.sjrt.GetCWDevData;
import com.yenlien.traceyun.plant.dock_device.sjrt.GetCWDevDataRJ;
import com.yenlien.traceyun.plant.dock_device.sjrt.GetCWDevDataSF;
import com.yenlien.traceyun.plant.entity.DevThreshold;
import com.yenlien.traceyun.plant.utils.MathUtils;
import com.yenlien.traceyun.webase.controller.BaseController;
import com.yenlien.traceyun.webase.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.yenlien.traceyun.plant.dock_device.DevState.*;

/**
 * @Date 2023/4/19
 * @Author jiaLong
 * @Descript 果园/物联网数据分析
 */

@RestController
@RequestMapping("/dataAnalyse")
@Api(tags = "一期和二期果园的数据分析")
public class FruitDataAnalyseController extends BaseController {


    @Autowired
    private OKQEnvDataDao okqEnvDataDao;

    @Autowired
    private ShiJiRuiTongDao shiJiRuiTongDao;

    @Autowired
    private EquipmentDao equipmentDao;

    @Autowired
    private KeBaiDao keBaiDao;

    @Autowired
    private XinFengXiangDao xinFengXiangDao;

    @Autowired
    private DevThresholdDao devThresholdDao;






    // 图形分析   长武：compId=cw   equId=设备序列号
    @ApiOperation(value = "图形分析,", notes = "参数：devId(设备ID), date(选择的时间,格式:yyyy-mm), paramName(参数名), 可选参数：compId(企业ID,不传则使用当前账号所属企业,一期果园长武=cw,三丰=sf)")
    @GetMapping(value = "/getGraphAnalyse")
    public Object getGraphAnalyse(@RequestParam String devId,
                                  @RequestParam String date,
                                  @RequestParam String paramName,
                                                String compId) {
        if(StringUtils.isBlank(compId)){
            compId = UserAuthUtil.getLoginUser().getCompanyId();
        }
        JSONObject result = new JSONObject();
        List<HashMap<String, String>> dayValList = genDayVal(date);
        List<JSONObject> graphAnalyseList = getGraphAnalyseList(compId, date, paramName, devId);
        Map<String, Object> normalVal = getNormalVal(devThresholdDao.getByCompIdAndEquIdAndType(compId, devId, paramName), paramName);
        result.put("dayValList", dayValList);       // 图表
        if(CollectionUtils.isEmpty(graphAnalyseList)){
            result.put("cnt", "0");                 // 采集总量
            result.put("normalCnt", "0");           // 正常值
            result.put("normalRatio", "0%");        // 正常值占比
            result.put("lowCnt", "0");              // 偏低值
            result.put("lowRatio", "0%");           // 偏低值占比
            result.put("highCnt", "0");             // 偏高值
            result.put("highRatio", "0%");          // 偏高值占比
            result.put("normal", normalVal.get("low") + "~" + normalVal.get("high") + normalVal.get("unit"));               // 正常范围
            return success(result);
        }
        dayValList = getDayValList(dayValList, graphAnalyseList);

        Integer lowCnt = 0;
        Integer highCnt = 0;
        Integer normalCnt = 0;
        for(JSONObject json : graphAnalyseList){
            Double paramVal = json.getDouble("paramVal");
            Double low = Double.valueOf(normalVal.get("low").toString());
            Double high = Double.valueOf(normalVal.get("high").toString());
            if(paramVal < low)
                lowCnt += 1;
            else if(paramVal > high)
                highCnt += 1;
            else
                normalCnt += 1;
        }
        int total = graphAnalyseList.size();
        result.put("cnt", total);
        result.put("normalCnt", normalCnt);
        result.put("normalRatio", MathUtils.percentage(normalCnt, total));
        result.put("lowCnt", lowCnt);
        result.put("lowRatio", MathUtils.percentage(lowCnt, total));
        result.put("highCnt", highCnt);
        result.put("highRatio", MathUtils.percentage(highCnt, total));
        result.put("dayValList", dayValList);
        result.put("normal", normalVal.get("low") + "~" + normalVal.get("high") + normalVal.get("unit"));
        return success(result);
    }



    // 小程序数据折线图
    @GetMapping(value = "/getLineMini")
    @ApiOperation(value = "小程序数据折线图,", notes = "参数：devId(设备ID), date(选择的时间,格式:yyyy-mm), 可选参数：compId(企业ID, 不传则使用当前账号所属企业,一期果园长武=cw,三丰=sf)")
    public Object getLineMini(    @RequestParam String devId,
                                  @RequestParam String date,
                                                String compId) {
        if(StringUtils.isBlank(compId)){
            compId = UserAuthUtil.getLoginUser().getCompanyId();
        }
        List<JSONObject> graphAnalyseList = getGraphAnalyseList(compId, date, null, devId);
        Map<String, List<JSONObject>> paramNameMap = graphAnalyseList.stream().collect(Collectors.groupingBy(x -> x.getString("paramName")));
        List<JSONObject> list = new ArrayList<>();
        for(String key : paramNameMap.keySet()){
            JSONObject json = new JSONObject();
            List<JSONObject> jsonObjectList = paramNameMap.get(key);
            JSONObject lastValue = jsonObjectList.get(jsonObjectList.size() - 1);
            json.put("paramName", key);
            json.put("unit", lastValue.getString("unit"));
            json.put("valNow", lastValue.getString("paramVal"));
            List<JSONObject> dataList = new ArrayList<>();
            for(JSONObject js : jsonObjectList){
                JSONObject object = new JSONObject();
                object.put("date", js.getString("cTime"));
                object.put("val", js.getString("paramVal"));
                dataList.add(object);
            }
            json.put("dataList", dataList);
            list.add(json);
        }
        return success(list);
    }






    // 获取土壤和气象设备 已经对应的参数
    @GetMapping(value = "/getDevList")
    @ApiOperation(value = "获取土壤和气象设备,", notes = "可选参数：compId(企业ID, 不传则使用当前账号所属企业,一期果园长武=cw,三丰=sf)")
    public Object getDevList(String compId) {
        if(StringUtils.isBlank(compId)){
            compId = UserAuthUtil.getLoginUser().getCompanyId();
        }
        List<DevDTO> devList = new ArrayList<>();
        if (StringUtils.isBlank(compId))
            compId = "cw";
        if(compId.length() < 10){
            if ("cw".equals(compId)){
                GetCWDevData.getToken();
                devList = GetCWDevData.getAllDev();
            }
            else if ("sf".equals(compId)){
                GetCWDevDataSF.getToken();
                devList = GetCWDevDataSF.getAllDev();
            } else if("qfx".equals(compId)){
                GetCWDevData.getToken();
                devList = GetCWDevData.getAllDev();
            }
            else if("rj".equals(compId)){
                GetCWDevDataRJ.getToken();
                devList = GetCWDevDataRJ.getAllDev();
            }
            devList = devList.stream().filter(x -> "气象监测站".equals(x.getDevType()) || "土壤墒情站".equals(x.getDevType())).collect(Collectors.toList());
        }else {
            devList = equipmentDao.findByCompanyId(compId).stream().filter(x -> EQU_TYPE_SOIL.equals(x.getType()) || EQU_TYPE_ENV.equals(x.getType())).map(x -> {
                DevDTO devDTO = new DevDTO();
//                devDTO.se tDevId(x.getSerial());
                devDTO.setDevId(x.getId());
                devDTO.setUpdateTime(x.getUpdateTime());
                devDTO.setDevName(x.getName());
                devDTO.setDevType(EQU_TYPE_SOIL.equals(x.getType()) ? "土壤墒情站" : "气象监测站");
                return devDTO;
            }).collect(Collectors.toList());
        }
        return success(devList);
    }


    // 根据设备ID获取参数列表
    @GetMapping(value = "/getParamList")
    @ApiOperation(value = "根据设备ID获取参数列表,", notes = "参数：devId(设备ID), 可选参数：compId(企业ID, 不传则使用当前账号所属企业,一期果园长武=cw,三丰=sf)")
    public Object getParamList(@RequestParam String devId, String compId) {
        if(StringUtils.isBlank(compId)){
            compId = UserAuthUtil.getLoginUser().getCompanyId();
        }
        if(compId.length() > 10){
            Equipment equipment = equipmentDao.findById(devId);
            if(equipment == null)
                throw new BusinessException("该设备不存在");
            if(EQU_MANUFACTURER_XFX.equals(equipment.getManufacturer())){
                return success(xinFengXiangDao.getParamNameList(devId));
            }else if(EQU_MANUFACTURER_KB.equals(equipment.getManufacturer())) {
                return success(keBaiDao.getParamNameList(devId));
            } else if(EQU_MANUFACTURER_SJRT.equals(equipment.getManufacturer())) {
                return success(shiJiRuiTongDao.getParamNameList(devId));
            } else if(EQU_MANUFACTURER_OKQ.equals(equipment.getManufacturer())) {
                return success(okqEnvDataDao.getParamNameList(devId));
            }
        }else {
            List<JSONObject> paramNameList = shiJiRuiTongDao.getParamNameList(devId).stream().filter(x -> StringUtils.isNotBlank(x.getString("paramName"))).collect(Collectors.toList());
            List<JSONObject> list1 = paramNameList.stream().filter(x -> x.getString("paramName").contains("土壤湿度") || x.getString("paramName").contains("土壤温度")).collect(Collectors.toList());
            List<JSONObject> list2 = paramNameList.stream().filter(x -> !x.getString("paramName").contains("土壤湿度") && !x.getString("paramName").contains("土壤温度")).collect(Collectors.toList());
            list1 = list1.stream().sorted(Comparator.comparing(x -> x.getString("paramName").substring(4, 6))).collect(Collectors.toList());
            list1.addAll(list2);
            return success(list1);
        }
        return success("");
    }






    @GetMapping(value = "/getTableAnalyse")
    @ApiOperation(value = "表格分析月平均值数据,", notes = "参数：devId(设备ID), date(选择的时间,格式:yyyy-mm), 可选参数：compId(企业ID, 不传则使用当前账号所属企业,一期果园长武=cw,三丰=sf)")
    public Object getTableAnalyse(@RequestParam String devId,
                                       @RequestParam String date,
                                       String compId) {
        List<JSONObject> analysis = new ArrayList<>();
        if(StringUtils.isBlank(compId)){
            compId = UserAuthUtil.getLoginUser().getCompanyId();
        }
        if(compId.length() > 10){
            Equipment equipment = equipmentDao.findById(devId);
            if(EQU_MANUFACTURER_XFX.equals(equipment.getManufacturer()))
                analysis = date.length() > 7 ? xinFengXiangDao.getAnalysisDay(date, compId, devId) : xinFengXiangDao.getAnalysis(date, compId, devId);
            else if(EQU_MANUFACTURER_KB.equals(equipment.getManufacturer()))
                analysis = date.length() > 7 ? keBaiDao.getAnalysisDay(date, compId, devId) : keBaiDao.getAnalysis(date, compId, devId);
            else if(EQU_MANUFACTURER_SJRT.equals(equipment.getManufacturer()))
                analysis = date.length() > 7 ? shiJiRuiTongDao.getAnalysisEquDay(date, devId, compId) : shiJiRuiTongDao.getAnalysisEqu(date, devId, compId);
            else if(EQU_MANUFACTURER_OKQ.equals(equipment.getManufacturer()))
                analysis = date.length() > 7 ? okqEnvDataDao.getAnalysisEquDay(date, devId, compId) : okqEnvDataDao.getAnalysisEqu(date, devId, compId);
            // 查找阈值
            List<DevThreshold> devThresholdList = devThresholdDao.getByCompIdAndEquId(compId, devId);
            if(!CollectionUtils.isEmpty(devThresholdList)){
                for(JSONObject json : analysis){
                    for(DevThreshold devThreshold : devThresholdList){
                        if(json.getString("paramName").equals(devThreshold.getName()))
                            json.put("normalRange", devThreshold.getLow() + "~" + devThreshold.getHigh() + devThreshold.getUnit());
                    }
                }
            }
        }else {
            analysis = date.length() > 7 ? shiJiRuiTongDao.getAnalysisEquDay(date, devId, compId) : shiJiRuiTongDao.getAnalysisEqu(date, devId, compId);
        }
        for(JSONObject json : analysis){
            if(StringUtils.isBlank(json.getString("normalRange"))){
                // 采用默认值
                Map normalRange = getNormalVal(null, json.getString("paramName"));
                json.put("normalRange", normalRange.get("low") + "~" + normalRange.get("high") + normalRange.get("unit"));
//                json.put("normalRange", getNormalVal(null, json.getString("paramName")));
            }
        }

        return success(analysis);
    }



    // 表格分析月平均值数据   当查询月分析时date参数为 年-月    查询日分析时date为 年-月-日
    @PostMapping(value = "/getCompare")
    @ApiOperation(value = "表格分析月平均值数据,", notes = "参数为JSON, 首次进入时参数案例 {\n" +
            "    \"devId\": \"4c9d0ded8215cj6701822e1de24567ui\",\n" +
            "    \"devName\": \"测试\",\n" +
            "    \"paramName\": \"总辐射\",\n" +
            "    \"compId\": \"2c9d0ded83c5fc250184835e13920090\",\n" +
            "    \"date\": \"2023-04\"\n}\n" +
            "。  同比时参数案例：{\n" +
            "    \"paramName\": \"总辐射\",\n" +
            "    \"compId\": \"2c9d0ded821a5f77018224eab3be0008\",\n" +
            "    \"date\": \"2023-03\",\n" +
            "    \"devIdList\": [{\"devId\": \"2c9d0ded821a232701822e1de2456745\", \"devName\": \"饲草基地C\"}, {\"devId\": \"2c9d0ded821a232701822e1de2ce05b1\", \"devName\": \"饲草基地A\"}]}\n" +
            "。  环比时参数案例：{\n" +
            "    \"devId\": \"2c9d0ded821a232701822e1de2456745\",\n" +
            "    \"devName\": \"测试\",\n" +
            "    \"paramName\": \"总辐射\",\n" +
            "    \"compId\": \"2c9d0ded821a5f77018224eab3be0008\",\n" +
            "    \"dateList\": [\"2023-01\", \"2023-02\", \"2023-03\", \"2023-04\"]}")
    public Object getCompare(@RequestBody @Validated CompareParamDTO compareParamDTO) {
        JSONObject result = new JSONObject();
        List<JSONObject> infoList = new ArrayList<>();
        Map<String, List<HashMap<String, String>>> lineList = new HashMap<>();
        List<String> dateList = compareParamDTO.getDateList();
        List<JSONObject> devList = compareParamDTO.getDevIdList();
        String compId = compareParamDTO.getCompId();
        if(StringUtils.isBlank(compId)){
            compId = UserAuthUtil.getLoginUser().getCompanyId();
            compareParamDTO.setCompId(compId);
        }
        String paramName = compareParamDTO.getParamName();
        DevThreshold devThreshold = devThresholdDao.getByCompIdAndEquIdAndType(compId, compareParamDTO.getDevId(), paramName);
        if(CollectionUtils.isEmpty(dateList) && CollectionUtils.isEmpty(devList)){
            // 首次进入页面不进行对比
            List<JSONObject> graphAnalyseList = getGraphAnalyseList(compId, compareParamDTO.getDate(), paramName, compareParamDTO.getDevId());
            List<HashMap<String, String>> dayValList = getDayValList(genDayVal(compareParamDTO.getDate()), graphAnalyseList);
            lineList.put(compareParamDTO.getDate(), dayValList);
            DoubleSummaryStatistics doubleSummaryStatistics = graphAnalyseList.stream()
                    .collect(Collectors.groupingBy(x -> x.getString("cTime").substring(0, 7), Collectors.summarizingDouble(x -> x.getDouble("paramVal")))).get(compareParamDTO.getDate());
            infoList.add(genInfoList(compareParamDTO, devThreshold, doubleSummaryStatistics, null));
        }else if(CollectionUtils.isEmpty(dateList) && !CollectionUtils.isEmpty(devList)){
            // 同比 同date和paramName且不同devId对比
//            devIdList.add(compareParamDTO.getDevId());  // 把自己也加入对比项
            for(JSONObject json : devList){
                List<JSONObject> graphAnalyseList = getGraphAnalyseList(compId, compareParamDTO.getDate(), paramName, json.getString("devId"));
                List<HashMap<String, String>> dayValList = getDayValList(genDayVal(compareParamDTO.getDate()), graphAnalyseList);
                lineList.put(json.getString("devName"), dayValList);
                compareParamDTO.setDevId(json.getString("devId"));
                DoubleSummaryStatistics doubleSummaryStatistics = graphAnalyseList.stream()
                        .collect(Collectors.groupingBy(x -> x.getString("devId"), Collectors.summarizingDouble(x -> x.getDouble("paramVal")))).get(compareParamDTO.getDevId());
                infoList.add(genInfoList(compareParamDTO, devThreshold, doubleSummaryStatistics, json.getString("devName")));
            }
        }else {
            // 环比
            for(String date : dateList){
                List<JSONObject> graphAnalyseList = getGraphAnalyseList(compId, date, paramName, compareParamDTO.getDevId());
                List<HashMap<String, String>> dayValList = getDayValList(genDayVal(date), graphAnalyseList);
                lineList.put(date, dayValList);
                compareParamDTO.setDate(date);
                DoubleSummaryStatistics doubleSummaryStatistics = graphAnalyseList.stream()
                        .collect(Collectors.groupingBy(x -> x.getString("cTime").substring(0, 7), Collectors.summarizingDouble(x -> x.getDouble("paramVal")))).get(compareParamDTO.getDate());
                infoList.add(genInfoList(compareParamDTO, devThreshold, doubleSummaryStatistics, null));
            }
        }
        result.put("mapLineList", lineList);        // 曲线
        result.put("infoList", infoList);           // 曲线下列表信息
        return success(result);
    }



    public JSONObject genInfoList(CompareParamDTO compareParamDTO, DevThreshold devThreshold, DoubleSummaryStatistics summaryStatistics, String devName){
        JSONObject analysisName = new JSONObject();
        if(compareParamDTO.getCompId().length() < 10){
            analysisName = shiJiRuiTongDao.getAnalysisName(compareParamDTO.getDate(), compareParamDTO.getDevId(), compareParamDTO.getParamName());
        }else {
            Equipment equipment = equipmentDao.findById(compareParamDTO.getDevId());
            if(EQU_MANUFACTURER_XFX.equals(equipment.getManufacturer())){
                analysisName = xinFengXiangDao.getAnalysisName(compareParamDTO.getDate(), compareParamDTO.getDevId(), compareParamDTO.getParamName());
            }else if(EQU_MANUFACTURER_KB.equals(equipment.getManufacturer())) {
                analysisName = keBaiDao.getAnalysisName(compareParamDTO.getDate(), compareParamDTO.getDevId(), compareParamDTO.getParamName());
            }
        }
        analysisName = analysisName == null ? new JSONObject() : analysisName;
        analysisName.put("low", summaryStatistics == null ? "0" : MathUtils.format(summaryStatistics.getMin()));
        analysisName.put("high", summaryStatistics == null ? "0" : MathUtils.format(summaryStatistics.getMax()));
        analysisName.put("avg", summaryStatistics == null ? "0" : MathUtils.format(summaryStatistics.getAverage()));

        analysisName.put("paramName", compareParamDTO.getParamName());
        analysisName.put("devName", StringUtils.isBlank(devName) ? compareParamDTO.getDevName() : devName);
        analysisName.put("devId", compareParamDTO.getDevId());
        analysisName.put("date", compareParamDTO.getDate());
        Map normalVal = getNormalVal(devThreshold, compareParamDTO.getParamName());
        analysisName.put("normalRange", normalVal.get("low") + "~" + normalVal.get("high") + normalVal.get("unit"));
        return analysisName;
    }

    public List<JSONObject> getGraphAnalyseList(String compId, String date, String paramName, String devId){
        List<JSONObject> graphAnalyseList = new ArrayList<>();
        if(compId.length() > 10){
            Equipment equipment = equipmentDao.findById(devId);
            Assert.isFalse(equipment == null, () -> new BusinessException("该设备不存在"));
            if(EQU_MANUFACTURER_XFX.equals(equipment.getManufacturer())){
                if(StringUtils.isBlank(paramName))
                    graphAnalyseList = xinFengXiangDao.getGraphAnalyse(date, devId);
                else
                    graphAnalyseList = xinFengXiangDao.getGraphAnalyse(date, paramName, devId);
            }else if(EQU_MANUFACTURER_KB.equals(equipment.getManufacturer())) {
                if(StringUtils.isBlank(paramName))
                    graphAnalyseList = keBaiDao.getGraphAnalyse(date, devId);
                else
                    graphAnalyseList = keBaiDao.getGraphAnalyse(date, paramName, devId);
            }else if(EQU_MANUFACTURER_SJRT.equals(equipment.getManufacturer())){
                if(StringUtils.isBlank(paramName))
                    graphAnalyseList = shiJiRuiTongDao.getGraphAnalyse(date, devId);
                else
                    graphAnalyseList = shiJiRuiTongDao.getGraphAnalyse(date, paramName, devId);
            }else if(EQU_MANUFACTURER_OKQ.equals(equipment.getManufacturer())){
                if(StringUtils.isBlank(paramName))
                    graphAnalyseList = okqEnvDataDao.getGraphAnalyse(date, devId);
                else
                    graphAnalyseList = okqEnvDataDao.getGraphAnalyse(date, paramName, devId);
            }
        }else {
            if(StringUtils.isBlank(paramName))
                graphAnalyseList = shiJiRuiTongDao.getGraphAnalyse(date, devId);
            else
                graphAnalyseList = shiJiRuiTongDao.getGraphAnalyse(date, paramName, devId);
        }
        return graphAnalyseList;
    }

    public List<HashMap<String, String>> getDayValList(List<HashMap<String, String>> dayValList, List<JSONObject> graphAnalyseList){
        //  按天数分组
        Map<String, DoubleSummaryStatistics> statisticsMap = graphAnalyseList.stream().filter(x -> !"风向值".equals(x.getString("paramName")))
                .collect(Collectors.groupingBy(x -> Short.valueOf(x.getString("cTime").substring(8, 10)).toString(), Collectors.summarizingDouble(x -> x.getDouble("paramVal"))));
        for(Map<String, String> map : dayValList){
            DoubleSummaryStatistics day = statisticsMap.get(map.get("day"));
            if(day != null)
                map.put("avgVal", MathUtils.format(day.getAverage()));
        }
        return dayValList;
    }

    public List<HashMap<String, String>> genDayVal(String date){
        // 参数 date格式 yyyy-mm
        LocalDate now = LocalDate.now();
        String nowDate = now.toString().substring(0, 7);
        if(Long.valueOf(date.replace("-", "")) > Long.valueOf(nowDate.replace("-", ""))){
            // 参数时间
            throw new BusinessException("只能选择当前及以前时间");
        }
        List<HashMap<String, String>> dayValList = new ArrayList<>();
        int days;
        if(nowDate.equals(date)){
            // 当前月: 1号至现在
            days = now.getDayOfMonth();
        }else {
            // 指定年月: 获取该月所有天
            String[] yearMonth = date.split("-");
            days = LocalDate.of(Integer.valueOf(yearMonth[0]), Integer.valueOf(yearMonth[1]), 1).lengthOfMonth();
        }
        Stream.iterate(1,  d -> d + 1).limit(days).forEach(f -> {
            HashMap map = new HashMap();
            map.put("day", f.toString());
            map.put("avgVal", "0");
            dayValList.add(map);
        });
        return dayValList;
    }



    public Map getNormalVal(DevThreshold devThreshold, String paramName){
        Map<String, Object> map = new HashMap<>();
        if (devThreshold == null) {
            switch (paramName) {
                case "大气压":
                    map.put("low", 90);
                    map.put("high", 105);
                    map.put("unit", "kpa");
                    break;
                case "数字气压":
                    map.put("low", 90);
                    map.put("high", 105);
                    map.put("unit", "kpa");
                    break;
                case "风速":
                    map.put("low", 0);
                    map.put("high", 17.1);
                    map.put("unit", "m/s");
                    break;
                case "光照强度":
                    map.put("low", 0);
                    map.put("high", 100000);
                    map.put("unit", "lux");
                    break;
                case "照度":
                    map.put("low", 0);
                    map.put("high", 100000);
                    map.put("unit", "lux");
                    break;
                case "降雨量":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "mm/min");
                    break;
                case "雨量":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "mm/min");
                    break;
                case "雨量累计":
                    map.put("low", 0);
                    map.put("high", 300);
                    map.put("unit", "mm/min");
                    break;
                case "总辐射":
                    map.put("low", 0);
                    map.put("high", 1000);
                    map.put("unit", "W/m2");
                    break;
                case "空气湿度":
                    map.put("low", 20);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "大气湿度":
                    map.put("low", 20);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "空气温度":
                    map.put("low", -4);
                    map.put("high", 37);
                    map.put("unit", "℃");
                    break;
                case "大气温度":
                    map.put("low", -4);
                    map.put("high", 37);
                    map.put("unit", "℃");
                    break;
                case "风向":
                    map.put("low", 0);
                    map.put("high", 360);
                    map.put("unit", "°");
                    break;
                case "风向值":
                    map.put("low", 0);
                    map.put("high", 360);
                    map.put("unit", "");
                    break;
                case "PM2.5":
                    map.put("low", 0);
                    map.put("high", 360);
                    map.put("unit", "°");
                    break;
                case "PM10":
                    map.put("low", 0);
                    map.put("high", 360);
                    map.put("unit", "°");
                    break;
                case "电导率":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "电压":
                    map.put("low", 0);
                    map.put("high", 1000);
                    map.put("unit", "v");
                    break;

                case "土壤氮":
                    map.put("low", 0);
                    map.put("high", 500);
                    map.put("unit", "mg/L");
                    break;
                case "氮离子":
                    map.put("low", 0);
                    map.put("high", 500);
                    map.put("unit", "mg/L");
                    break;
                case "氮":
                    map.put("low", 0);
                    map.put("high", 500);
                    map.put("unit", "mg/L");
                    break;
                case "土壤温度":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "土壤温度10cm":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "10cm土壤温度":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "土壤温度20cm":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "20cm土壤温度":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "土壤温度30cm":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "土壤温度40cm":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "30cm土壤温度":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "土壤温度50cm":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "50cm土壤温度":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "℃");
                    break;
                case "土壤磷":
                    map.put("low", 0);
                    map.put("high", 500);
                    map.put("unit", "mg/L");
                    break;
                case "磷":
                    map.put("low", 0);
                    map.put("high", 500);
                    map.put("unit", "mg/L");
                    break;
                case "磷离子":
                    map.put("low", 0);
                    map.put("high", 500);
                    map.put("unit", "mg/L");
                    break;
                case "土壤钾":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "mg/L");
                    break;
                case "钾":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "mg/L");
                    break;
                case "钾离子":
                    map.put("low", 0);
                    map.put("high", 50);
                    map.put("unit", "mg/L");
                    break;
                case "土壤湿度":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤湿度10cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤水分10cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "10cm土壤湿度":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤湿度20cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤水分20cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "20cm土壤湿度":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤湿度30cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤水分30cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "30cm土壤湿度":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤水分40cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤湿度50cm":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "50cm土壤湿度":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤EC":
                    map.put("low", 0);
                    map.put("high", 1000);
                    map.put("unit", "uS/cm");
                    break;
                case "土壤氧气":
                    map.put("low", 0);
                    map.put("high", 100);
                    map.put("unit", "%");
                    break;
                case "土壤盐分":
                    map.put("low", 0);
                    map.put("high", 5000);
                    map.put("unit", "mg/L");
                    break;
                case "盐分":
                    map.put("low", 0);
                    map.put("high", 5000);
                    map.put("unit", "mg/L");
                    break;
                case "土壤PH":
                    map.put("low", 0);
                    map.put("high", 14);
                    map.put("unit", "PH");
                    break;
                default:
                    throw new BusinessException("参数名错误");
            }
        } else {
            map.put("low", devThreshold.getLow());
            map.put("high", devThreshold.getHigh());
            map.put("unit", devThreshold.getUnit());
        }
        return map;
    }



    public static void main(String[] args) {


        System.out.println("土壤湿度10cm".substring(4, 6));
    }








}
